<?php

Class LevelAction extends Action {
	public function index(){
		$this->level = M('UserLevel')->where("id>2")->select();
		$this->display();
	}

	public function edit(){
		if(IS_POST){
			$condition['id'] = intval(mysql_escape_string(I('id')));
			$data['level'] = mysql_escape_string(I('level'));
			$data['recordprice'] = intval(mysql_escape_string(I('recordprice')));
			$data['subprice'] = intval(mysql_escape_string(I('subprice')));
			$data['discussprice'] = intval(mysql_escape_string(I('discussprice')));
			$save = M('UserLevel')->where($condition)->save($data);

			if($save !==false){
				$this->ajaxReturn(array("status"=>1),"JSON");
			}else{
				$this->ajaxReturn(array("status"=>0),"JSON");
			}
			exit;
		}
		$condition['id']=mysql_escape_string(I('id'));
		$this->level = M('UserLevel')->where($condition)->find();
		$this->display();
	}

	public function add(){
		if(IS_POST){
			$data['level'] = mysql_escape_string(I('level'));
			$data['recordprice'] = intval(mysql_escape_string(I('recordprice')));
			$data['subprice'] = intval(mysql_escape_string(I('subprice')));
			$data['discussprice'] = intval(mysql_escape_string(I('discussprice')));
			$add = M('UserLevel')->add($data);

			if($add){
				$this->ajaxReturn(array("status"=>1),"JSON");
			}else{
				$this->ajaxReturn(array("status"=>0),"JSON");
			}
			exit;
		}
		$this->display();
	}
}